package group.raber.base.listener;

import group.raber.saber.holder.WebHolder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@ServletComponentScan
@WebListener
public class WebHolderListener implements ServletContextListener {

    public void contextDestroyed(ServletContextEvent event) {

    }

    public void contextInitialized(ServletContextEvent event) {
        WebHolder.setServletContext(event.getServletContext());
        System.out.println("-------AAA--------:"+event.getServletContext().getContextPath());
//        ContextLoader loader = new ContextLoader();
//        loader.initWebApplicationContext(event.getServletContext());
//        WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext())
//                .getAutowireCapableBeanFactory().autowireBean(this);
    }

}
